
use "CES_replication.dta", clear

********************************
****Plot each prompt by party***
********************************

twoway histogram longfor if pid3lean==1, width(1) fcolor(blue%50) lc(blue) || histogram longfor if pid3lean==2, width(1) fcolor(red%50) lc(red) scheme(s1mono) legend(order(1 "Democratic" 2 "Republican")) ylabel(0 (.1) 0.5) xtitle(Long for the good olf days --- never - always) 
graph save "longfor_hist.gph", replace

twoway histogram feelnostalgia if pid3lean==1, width(1) fcolor(blue%50) lc(blue) || histogram feelnostalgia if pid3lean==2, width(1) fcolor(red%50) lc(red) scheme(s1mono) legend(order(1 "Democratic" 2 "Republican")) ylabel(0 (.1) 0.5) xtitle(How often do you feel nostalgic --- never - always)
graph save "feelnostalgia_hist.gph", replace

twoway histogram usculture if pid3lean==1, width(1) fcolor(blue%50) lc(blue) || histogram usculture if pid3lean==2, width(1) fcolor(red%50) lc(red) scheme(s1mono) legend(order(1 "Democratic" 2 "Republican")) ylabel(0 (.1) 0.5) xtitle(American culture and way of life --- better - worse)
graph save "usculture_hist.gph", replace

twoway histogram uspolsystem if pid3lean==1, width(1) fcolor(blue%50) lc(blue) || histogram uspolsystem if pid3lean==2, width(1) fcolor(red%50) lc(red) scheme(s1mono) legend(order(1 "Democratic" 2 "Republican")) ylabel(0 (.1) 0.5) xtitle(American political system --- better - worse)
graph save "uspolsystem_hist.gph", replace

twoway histogram useconsystem if pid3lean==1, width(1) fcolor(blue%50) lc(blue) || histogram useconsystem if pid3lean==2, width(1) fcolor(red%50) lc(red) scheme(s1mono) legend(order(1 "Democratic" 2 "Republican")) ylabel(0 (.1) 0.5) xtitle(America's economic system --- better - worse)
graph save "useconystem_hist.gph", replace

twoway histogram betterplace if pid3lean==1, width(1) fcolor(blue%50) lc(blue) || histogram betterplace if pid3lean==2, width(1) fcolor(red%50) lc(red) scheme(s1mono) legend(order(1 "Democratic" 2 "Republican")) ylabel(0 (.2) 1) xtitle(The world used to be a better place --- disagree - agree)
graph save "betterplace_hist.gph", replace

grc1leg longfor_hist.gph feelnostalgia_hist.gph usculture_hist.gph uspolsystem_hist.gph useconystem_hist.gph betterplace_hist.gph, rows(3)


*****************************
****Create nostalgia scale***
*****************************

factor longfor feelnostalgia usculture uspolsystem useconsystem betterplace, pcf
rotate
predict nostalgia pessimism

sum nostalgia
replace nostalgia = (nostalgia-`r(min)') / (`r(max)'-`r(min)')
sum pessimism
replace pessimism = (pessimism-`r(min)') / (`r(max)'-`r(min)')


**********************************************
****Regress open ends on nostalgia measure****
**********************************************

label variable bigotry "Bigotry"
label variable madeup "Never existed"
label variable era "Specific era"
label variable simpler "Simple life"
label variable economics "Stronger economy"
label variable politicsnew "Better politics"
label variable politeness "Higher morality"
label variable technology "Less technology"
label variable crime "Lower crime"

svyset [weight=teamweight]

svy: reg nostalgia bigotry madeup era simpler economics politicsnew politeness technology crime 
est sto factor1
svy: reg pessimism bigotry madeup era simpler economics politicsnew politeness technology crime
est sto factor2

coefplot factor1 factor2, xline(0, lc(red)) headings(bigotry="Not nostalgic" era="Nostalgic", labsize(small)) drop(_cons) coeflabels(, labsize(vsmall)) scheme(s1mono) levels(95 90) msize(small) legend(order(3 "Generic nostalgia" 6 "Domain-specific")) xlabel(-.4 (.1) .2)
graph save "openends_nostalgia.gph", replace 


*************************************
****Plot nostalgia scale by party****
*************************************

twoway histogram nostalgia if pid3lean==1, width(.1) fcolor(blue%50) lc(blue) start(0) || histogram nostalgia if pid3lean==2, width(.1) fcolor(red%50) lc(red) scheme(s1mono) legend(order(1 "Democratic" 2 "Republican")) xtitle(Nostalgia Scale) xscale(range(-.02 1.02)) xlabel(0 (.2) 1) start(0) ylabel(0 (1) 3)
graph save "nostalgia_hist_byparty.gph", replace 

twoway histogram pessimism if pid3lean==1, width(.1) fcolor(blue%50) lc(blue) start(0) || histogram pessimism if pid3lean==2, width(.1) fcolor(red%50) lc(red) scheme(s1mono) legend(order(1 "Democratic" 2 "Republican")) xtitle(Dimension 2 -- Domain-Specific Nostalgia) xscale(range(-.02 1.02)) xlabel(0 (.2) 1) start(0) ylabel(0 (1) 3)
graph save "pessimism_hist_byparty.gph", replace 


*********************************
****Determinants of nostalgia****
*********************************

*create alternative nostalgia measure for robustness
alpha longfor feelnostalgia usculture uspolsystem useconsystem betterplace, generate(nostalgia_alt)
sum nostalgia_alt
replace nostalgia_alt = (nostalgia_alt-`r(min)') / (`r(max)'-`r(min)')


svy: reg pessimism pid7 ideo5 pew_religimp newsint foxnews cnn_msnbc faminc_new educ retired unemployed investor ownhome badlifeevent health cat_age woman i.race3 hispanic child18 bornintheusa city
est sto pessimism_reg 

svy: reg nostalgia pid7 ideo5 pew_religimp newsint foxnews cnn_msnbc faminc_new educ retired unemployed investor ownhome badlifeevent health cat_age woman i.race3 hispanic child18 bornintheusa city
est sto nostalgia_reg

coefplot, drop(_cons) xline(0, lc(red)) levels(95 90) scheme(s1mono) headings( pid7="Beliefs" newsint="Media Consumption" faminc_new="Wellbeing" cat_age="Demographics", labsize(small)) coeflabels(pid7="Party ID" pew_religimp="Importance of religion" newsint="Political interest" foxnews="Watched Fox News" cnn_msnbc="Watched CNN or MSNBC" retired="Employment status - retired" unemployed="Employment status - unemployed" badlifeevent="Bad life event" cat_age="Age" woman="Gender - woman" 2.race3="Race - Black" 3.race3="Race - other" hispanic="Ethnicity - Hispanic" child18="Have children under 18" bornintheusa="Born in the U.S." city="Residence - urban",labsize(vsmall)) xlabel(-.15 (.05) .15) msize(small)
graph save "determinants_nostalgia.gph", replace 


svy: reg nostalgia_alt pid7 ideo5 pew_religimp newsint foxnews cnn_msnbc faminc_new educ retired unemployed investor ownhome badlifeevent health cat_age woman i.race3 hispanic child18 bornintheusa city
est sto alt1

svy: reg longfor pid7 ideo5 pew_religimp newsint foxnews cnn_msnbc faminc_new educ retired unemployed investor ownhome badlifeevent health cat_age woman i.race3 hispanic child18 bornintheusa city
est sto alt2

esttab nostalgia_reg alt1 alt2 using "alt_table_nostalgia.tex", se r2 wide starlevels($^+$ 0.1 $^*$ 0.05 $^{**}$ 0.01) label replace


esttab pessimism_reg using "alt_table_pessimism.tex", se r2 wide starlevels($^+$ 0.1 $^*$ 0.05 $^{**}$ 0.01) label replace

******************
***Vote choice 

mlogit houseparty nostalgia pid7 ideo5 faminc_new educ cat_age woman hispanic [pweight=teamweight]
est sto votechoice
margins, at(nostalgia=(0(0.2)1))
marginsplot, scheme(s1mono) legend(order(4 "Democratic" 5 "Other" 6 "Republican") rows(1)) title("") ytitle("Probability of voting for each party") xtitle("Nostalgia")
esttab votechoice using "votechoice_table.tex", se pr2 scalar(chi2) noomit unstack nogaps starlevels($^+$ 0.1 $^*$ 0.05 $^{**}$ 0.01) label replace
 
 
svy: mlogit houseparty c.nostalgia##c.pid7 ideo5 faminc_new educ cat_age woman hispanic 
esttab using "votechoice_int_table.tex", se pr2 scalar(chi2) noomit unstack nogaps starlevels($^+$ 0.1 $^*$ 0.05 $^{**}$ 0.01) label replace

mlogit houseparty pessimism pid7 ideo5 faminc_new educ cat_age woman hispanic [pweight=teamweight]
est sto votechoice_pessimism
esttab votechoice_pessimism using "votechoice_pess.tex", se pr2 scalar(chi2) noomit unstack nogaps starlevels($^+$ 0.1 $^*$ 0.05 $^{**}$ 0.01) label replace

svy: mlogit houseparty nostalgia_alt pid7 ideo5 faminc_new educ cat_age woman hispanic 
est sto vote_alt1
svy: mlogit houseparty longfor pid7 ideo5 faminc_new educ cat_age woman hispanic 
est sto vote_alt2

esttab vote_alt1 vote_alt2 using "vote_alt_table.tex", se pr2 scalar(chi2) noomit unstack nogaps starlevels($^+$ 0.1 $^*$ 0.05 $^{**}$ 0.01) label replace

